#include <stdio.h>
#include <stdlib.h>

#define MAXSIZE 250	
#define MAXFILENAME 256

void doCommand(char command);
void fill(int x, int y, char r, char c, char direction);

int M, N;
char Canvas[MAXSIZE][MAXSIZE];
char FileName[MAXFILENAME];
char *fn = FileName;

int main(int argc, char **argv){
    char command;
    #ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w+", stdout);
    #endif
    while(scanf("%c", &command)==1 && (command != 'x' || command != 'X'))
	doCommand(command);
    return(0);
}

void doCommand(char command){
    int i, j, x, y, x1, y1, tmp;
    char c;
    switch(command){
	case 'i':
	case 'I':
	    scanf("%d %d", &M, &N);
	case 'c':
	case 'C':
	    for(j = 0; j < N; j++)
		for(i = 0; i < M; i++)
		    Canvas[i][j] = 'O';
	    break;
	case 'l':
	case 'L':
	    scanf("%d %d %c", &x, &y, &c);
	    Canvas[x-1][y-1] = c;
	    break;
	case 'v':
	case 'V':
	    scanf("%d %d %d %c", &x, &y, &y1, &c);
	    if(y > y1){
		tmp = y;
		y = y1;
		y1 = tmp;
	    }
	    for(j = y-1; j < y1; j++)
		Canvas[x-1][j] = c;		
	    break;
	case 'h':
	case 'H':
	    scanf("%d %d %d %c", &x, &x1, &y, &c);
	    if(x > x1){
		tmp = x;
		x = x1;
		x1 = tmp;
	    }
	    for(i = x-1; i < x1; i++)
		Canvas[i][y-1] = c;
	    break;
	case 'k':
	case 'K':
	    scanf("%d %d %d %d %c", &x, &y, &x1, &y1, &c);
	    if(x > x1){
		tmp = x;
		x = x1;
		x1 = tmp;
	    }
	    if(y > y1){
		tmp = y;
		y = y1;
		y1 = tmp;
	    }
	    for(i = x-1; i < x1; i++)
		for(j = y-1; j < y1; j++)
		    Canvas[i][j] = c;
	    break;
	case 'f':
	case 'F':
	    scanf("%d %d %c", &x, &y, &c);
	    x--; y--;
	    fill(x, y, Canvas[x][y], c, 'a');
	    
	    break;
	case 's':
	case 'S':
	    scanf("%s", fn);
	    printf("%s\n", fn);
	    for(j = 0; j < N; j++){
		for(i = 0; i < M; i++)
		    printf("%c", Canvas[i][j]);
		printf("\n");
	    }	    
	    break;
    }
}

void fill(int x, int y, char r, char c, char direction){
    if(Canvas[x][y] == r){
	Canvas[x][y] = c;
	if(('a' || 'u' || 'l' || 'r') && y < N-1)
	    fill(x, y+1, r, c, 'u');
	if(('a' || 'd' || 'l' || 'r') && y > 0)
	    fill(x, y-1, r, c, 'd');
	if(('a' || 'l' || 'u' || 'd') && x < M-1)
	    fill(x+1, y, r, c, 'l');
	if(('a' || 'r' || 'u' || 'd') && x > 0)
	    fill(x-1, y, r, c, 'r');
    }
}
